const {findDataByPage} = require('../server/util/db-util')
const {setStatus, setShareList, initShareMsg, setOneShare} = require('../server/model/share/getShare')
let {shareMsg} = require('../server/model/share/shareMsg')

function test(i) {
    return new Promise(function (resolve,reject) {
       setTimeout(function () {
           console.log(i)
           resolve(i)
       },200)
    })
}

async function getPublicShare(page = 1, size = 5) {
    let shareList = await findDataByPage('share', '*', (page - 1) * size, (page) * size)
    initShareMsg(shareMsg)
    setStatus(shareMsg, 1)
    const promises = shareList.map((value) => {
        return new Promise(async function (resolve, reject) {
            resolve(setOneShare(value))
        })
    })
    // let te = []
    // for(let i=0;i<5;i++){
    //     te.push(test(i))
    // }
    let data = await Promise.all(promises)
    console.log(data)
}

module.exports = getPublicShare